home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Tools Goodies / AEGizmos 1.4.1 / Demo app / AEGizmos test.c next >
Encoding:
C/C++ Source or Header  |  1992-07-21  |  3.0 KB  |  123 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    AppleEvent Builder test program
  3.  *    by Jens Peter Alfke
  4.  *
  5.  *    Copyright ©1991 Apple Computer, Inc. All rights reserved.
  6.  *
  7.  *    APPLE CONFIDENTIAL
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "AppleEvents.h"
  12. #include "AEBuild.h"
  13. #include "AEBuildGlobals.h"
  14. #include "AEPrint.h"
  15.  
  16.  
  17. char *AEBuild_ErrMsgs[] = {
  18.     "[No Error!]",
  19.     "Illegal character",
  20.     "Unexpectedly fell off end of line",
  21.     "Extra stuff past end of descriptor",
  22.     "“-” not followed by a number",
  23.     "Missing close “'”",
  24.     "Illegal digit in hex string",
  25.     "Hex string has an odd number of digits",
  26.     "Missing “»”",
  27.     "Hex string must be coerced to some data type",
  28.     "Missing “””",
  29.     "Illegal descriptor",
  30.     "Illegal data value inside parentheses",
  31.     "Missing “)” after data value",
  32.     "Missing “]”",
  33.     "Missing “,” or “]”",
  34.     "Missing keyword in record element",
  35.     "Missing “:” after keyword in record element"
  36. };
  37.  
  38.  
  39. const char SampleString[] =
  40. "obj{ want:type('line'),"
  41.      "from: obj{ want: type('line'), from: docu(), form: 'test',"
  42.                 "seld: logi{"
  43.                             "term: [comp{ relo:=, obj1:“April”,"
  44.                                          "obj2:"
  45.                                "obj{ want:type('word'), from:exmn(), form:indx, seld:1 }},"
  46.                                    "comp{ relo:=, obj1:“is”,"
  47.                                          "obj2:"
  48.                                "obj{ want:type('word'), from:exmn(), form:indx, seld:2 }}"
  49.                                   "],"
  50.                             "logc:AND"
  51.                           "}"
  52.               "},"
  53.     "form: 'indx',"
  54.     "seld: 1"
  55. "}";
  56.  
  57.  
  58. void main( void );
  59.  
  60.  
  61. void
  62. main( void )
  63. {
  64.     OSErr err;
  65.     AEDesc desc;
  66.     char str[1024];
  67.     OSType sig = 'Targ';
  68.     Boolean isEvent;
  69.     
  70.     puts(
  71. "This program lets you fool around with AEBuild() and AEPrint().\n\
  72. At the '>' prompt, enter a format string. AEBuild will use the\n\
  73. string as the template for an AEDesc, AEPrint will convert the\n\
  74. AEDesc back into a string, and the program will spit out the\n\
  75. resulting string. If AEBuild reports a syntax error, you'll see the\n\
  76. approximate location of the error and a message. If either routine\n\
  77. returns any other error, you'll see the error code.\n");
  78.     puts(
  79. "To build an entire event, prefix the string with a “\\”.\n\
  80. \n\
  81. To build and print a fairly complex sample descriptor, enter a blank line.\n");
  82.     
  83.     do{
  84.         printf("> ");
  85.         gets(str);
  86.         
  87.         isEvent = str[0]=='\\';
  88.         if( isEvent )
  89.             err= AEBuildAppleEvent(    'Some','Evnt',
  90.                                     typeApplSignature,&sig,sizeof(sig),
  91.                                     kAutoGenerateReturnID,kAnyTransactionID,
  92.                                     &desc, str+1 );
  93.         else if( !str[0] ) {
  94.             puts("How's this for a descriptor string:");
  95.             printf("  ");
  96.             puts(SampleString);
  97.             err= AEBuild(&desc, SampleString);
  98.  
  99.         } else
  100.             err= AEBuild(&desc, str);
  101.         
  102.         if( err ) {
  103.             long i;
  104.             
  105.             for( i=0; i<AEBuild_ErrPos+2; i++ )
  106.                 putchar(' ');
  107.             printf("^\n\t");
  108.             if( err==aeBuild_SyntaxErr )
  109.                 printf("Syntax error: %s\n", AEBuild_ErrMsgs[AEBuild_ErrCode]);
  110.             else
  111.                 printf("Error %d in AEBuild!\n",err);
  112.         } else {
  113.             printf("\tBuilt %s. Now formatting it …",
  114.                         isEvent ?"Apple event" :"descriptor" );
  115.             err= AEPrint(&desc, str,sizeof(str));
  116.             if( err )
  117.                 printf(" Error %d in AEPrint\n");
  118.             else
  119.                 printf(" ok. Result:\n\t\t%s\n", str);
  120.         }
  121.     }while( true );
  122. }
  123.